package com.vogue.supplymall.order.domain.provider;

import com.vogue.ssm.database.provider.BaseSqlProvider;
import com.vogue.supplymall.common.domain.dto.RefundMaxCountInfo;

public class RefundMaxqQuantity extends BaseSqlProvider{
	public String find(RefundMaxCountInfo refundMaxCountInfo) {
		StringBuilder sql=new StringBuilder();
		sql.append("SELECT ")
			.append(" sum(rd.refundquantity)  as refundquantity")
			.append(" from `order` o")
			.append(" join order_item oi on oi.orderid=o.id")
			.append(" join order_item_product oip on oip.orderid=o.id and oip.orderitemid=oi.id ")
			.append(" join refund_order ro on ro.orderid=o.id")
			.append(" join refund_detail rd on rd.refundid=ro.id and rd.oiid=oi.id and rd.oipid=oip.id")
			.append(" join refund_status rs on rs.refundid=ro.id and rs.refundstatus<>2")
			.append(" where o.id=#{orderid} and oip.id=#{oipid}")
			.append(" group by o.id,oip.productid");
		
		return sql.toString();
	}
	
}
